
(function () {
    'use strict';

    angular.module('app.maquinas')
        .service('MaquinasService', ['restBaseUrl', '$http', MaquinasService]);

    function MaquinasService (restBaseUrl, $http) {

        var serviceName = 'MaquinasService.svc/';

        this.listar = function () {
            var req = {
                method: 'GET',
                url: restBaseUrl + serviceName + 'Listar'
            };

            return $http(req);
        };


        this.eliminar= function(idMaquina){

            var req = {
                method: 'DELETE',
                url: restBaseUrl + serviceName + 'Delete',
                headers: {
                    "Content-Type": "application/json"
                },
                data: {id : idMaquina}

            };
            return $http(req);

        };

        this.crearMaquina = function(data){
            var req = {
                method: 'POST',
                url: restBaseUrl + serviceName + 'Create',
                headers: {
                    "Content-Type": "text/plain"
                },
                data : data
            };

            return $http(req);
        };

        this.listarTiposMaquinas = function(){
            var serviceNameTmp = 'TipoMaquinaService.svc/';
            var req = {
                method: 'GET',
                url: restBaseUrl + serviceNameTmp + 'Listar'
            };

            return $http(req);
        };

        this.buscarPorId = function(idMaquina){
            var url =  restBaseUrl + serviceName + 'BuscarPorId';

            return $http.get(url,{
                params: {
                    id: idMaquina
                }
            });
        };


        this.update = function(maquina) {
            console.log(maquina);
            var req = {
                method: 'PUT',
                url: restBaseUrl + serviceName + 'Update',
                data: angular.toJson(maquina),
                headers: {
                    "Content-Type": "text/plain"
                }
            };
            return $http(req);
        };

    }
})();